using UnityEngine;

namespace GameToolkit.UI
{
    [AddComponentMenu(""), DisallowMultipleComponent]
    public class UISkinRecursive : MonoBehaviour
    {
        UISkinAsset.SkinController mController;
        System.Action mResetor;

        public void SetController(UISkinAsset.SkinController ct)
        {
            mController = ct;
            if (ct == null)
            {
                mResetor = null;
            }
            else
            {
                mResetor = ResetController;
            }
        }

        private void ResetController()
        {
            if (mController != null && this != null)
                mController.Reset();
        }

        private void OnTransformChildrenChanged()
        {
            if (mResetor != null)
            {
                MainThread.RunOnMainThread(mResetor, EExecuteEvent.LateUpdate);
            }
        }

    }
}
